//
//  ClassifyCollectionReusableView.m
//  7.23 半糖
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 高雅馨. All rights reserved.
//

#import "ClassifyCollectionReusableView.h"
#import "classifyCollectionViewCell.h"

@interface ClassifyCollectionReusableView ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UICollectionView * collectionView;
@property (nonatomic, strong) UIButton *headerButton;
@end
@implementation ClassifyCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _headerButton = [UIButton buttonWithType: UIButtonTypeCustom];
        _headerButton.frame = CGRectMake(5, 0, 100, 50);
        [_headerButton setImage:[UIImage imageNamed:@"category_icon"] forState:UIControlStateNormal];
        [_headerButton setTitle:@"分类" forState:UIControlStateNormal];
        [_headerButton setTitleColor:[UIColor colorWithRed:0.94 green:0.41 blue:0.38 alpha:1.00] forState:UIControlStateNormal];
        [self addSubview:_headerButton];
        [self creatCollection];
    }
    return self;
}
// 分类
-(void)creatCollection {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((CGRectGetWidth(self.frame) - 30) / 2, (CGRectGetHeight(self.frame)  - 50 - 40)/ 3);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 50, self.frame.size.width , CGRectGetHeight(self.frame) - 50) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self addSubview:_collectionView];
    [self.collectionView registerClass:[classifyCollectionViewCell class] forCellWithReuseIdentifier:@"classifyCell"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    classifyCollectionViewCell *classify = [collectionView dequeueReusableCellWithReuseIdentifier:@"classifyCell" forIndexPath:indexPath];
    classify.myImageView.image = [UIImage imageNamed:@"default_user_icon"];
    return classify;
}
@end
